home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 June / CHIP Haziran 2001.iso / prog / share / 17 / dings_e.exe / Compiler / Bin / OpenGLRainbows.h < prev    next >
C/C++ Source or Header  |  2001-02-07  |  7KB  |  211 lines

  1. // OpenGLRainbows.h: Schnittstelle fⁿr die Klasse OpenGLRainbows.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4.  
  5. #if !defined(AFX_OPENGLRAINBOWS_H__266EBDA0_35ED_11D4_9493_F737DDF20444__INCLUDED_)
  6. #define AFX_OPENGLRAINBOWS_H__266EBDA0_35ED_11D4_9493_F737DDF20444__INCLUDED_
  7.  
  8. #if _MSC_VER > 1000
  9. #pragma once
  10. #endif // _MSC_VER > 1000
  11.  
  12.  
  13. #ifndef    OPENGL_RAINBOWS_INCLUDED_09_12_2000_16_15
  14. #define OPENGL_RAINBOWS_INCLUDED_09_12_2000_16_15
  15.  
  16. #ifdef _WINDOWS_
  17. #include "windows.h"
  18. #else
  19. #include "afxwin.h"
  20. #endif
  21. #include <gl\gl.h>            // Header File For The OpenGL32 Library
  22. #include <gl\glu.h>            // Header File For The GLu32 Library
  23. #include <gl\glaux.h>        // Header File For The Glaux Library
  24.  
  25. #include "GFFileSystem.h"
  26. #include <mmsystem.h>
  27.  
  28. #define GLR_OK                0x0000
  29. #define GLR_MAX_TEXTURES    0x00FF
  30. #define GLR_MAX_SURFACE        0x000F
  31. #define GLR_MAX_PARTICLE    0x0400
  32.  
  33.  
  34. #define MAKEGRAYCOLOR(a) {int b=(int)((GetRValue(a)*0.30) + (GetGValue(a)*0.59) + (GetBValue(a)*0.11)); a=RGB(b,b,b);}
  35. #ifndef ZeroStruct
  36.     #define ZeroStruct(a) ::memset(&a, 0, sizeof(a))
  37. #endif
  38.  
  39. struct OPENGL_PARTICLE
  40. {
  41.     int        amount; // Amount of Particles to Create
  42.     int        type; // 0-Triangluar
  43.     float    age; // in 1/1000 sec
  44.     float    speedx; // in pixels/1/1000 sec
  45.     float    speedy; // in pixels/1/1000 sec
  46.     float    movex; // Additional Movement X - Wind
  47.     float    movey; // Additional Movement Y - Gravity
  48.     float    accx; // accellerate X
  49.     float    accy; // accellerate Y
  50.     float    posx; // Position
  51.     float    posy; // Position
  52.  
  53.     float    c_red;        // Red   [0; 0.5]
  54.     float    c_green;    // Green [0; 0.5]
  55.     float    c_blue;        // Blue  [0; 0.5]
  56. };
  57.  
  58. struct OPENGL_SPRITEFX
  59. {
  60. // SpriteFX
  61.     float        alpha;
  62.     float        angle;
  63.     short        dx;
  64.     short        dy;
  65.     COLORREF    teint;
  66. };
  67.  
  68. extern float    qsin[360];
  69. extern float    qcos[360];
  70.  
  71.  
  72. class OpenGLRainbows  
  73. {
  74. /////////////////////////////////////////////////////////////////////////////////////////
  75. // FUNCTIONS
  76. /////////////////////////////////////////////////////////////////////////////////////////
  77. public:
  78.     OpenGLRainbows();
  79.     virtual ~OpenGLRainbows();
  80.  
  81.     HRESULT    Init(HWND hwnd, int width, int height, int bpp, unsigned short fps=5); // Init OpenGLRainbows. Returns GLR_OK if OK.
  82.     bool    IsActive()            {return m_IsActive;}        // Can perform rendering?
  83.     bool    DoFullscreen();
  84.     bool    DoWindowed();
  85.     bool    HideWindow();
  86.     unsigned short ConstFlip() {return m_ConstFlip;}
  87.     void    ChangeSize(GLsizei w, GLsizei h);// Change viewing volume and viewport.  Called when window is resized
  88.  
  89. private:
  90.     void    SetupRC(void);                    // Initialize the Rendering Context
  91.     void    SetDCPixelFormat(HDC hDC);        // Set Pixel Format function - forward declaration
  92.     HPALETTE GetOpenGLPalette(HDC hDC);    // For Palettized Viewport...
  93.  
  94. // Sprite Operations
  95. ///////////////////////////////////////////////////////////////////
  96. public:    
  97.  
  98.     BOOL LoadSprite(GLuint num, LPCTSTR szFileName, COLORREF colorkey); // Load a Texture as a Sprite
  99.  
  100.     void DrawSprite(short num, short x, short y); // Draws a Single Sprite with Cookie
  101.     void ZoomSprite(short num, short x, short y, short wx, short wy); // Zooms Sprite to new extents
  102.     void RotoSprite(short num, short x, short y, short angle);// Draws a Sprite with Rotation
  103.  
  104.     void DrawSpriteNC(short num, short x, short y); // Draws a Single Sprite with NO Cookie
  105.     void ZoomSpriteNC(short num, short x, short y, short wx, short wy); // Zooms Sprite to new extents NO Cookie
  106.     void RotoSpriteNC(short num, short x, short y, short angle);// Draws a Sprite with Rotation NO Cookie
  107.  
  108.     void DrawSpriteAB(short num, short x, short y, GLfloat alpha); // Draws a Single Sprite with AlphaBlending
  109.     void ZoomSpriteAB(short num, short x, short y, short wx, short wy, GLfloat alpha); // Zooms Sprite to new extents Alpha Blending
  110.     void RotoSpriteAB(short num, short x, short y, short angle, GLfloat alpha);// Draws a Sprite with Rotation with Alpha Blending
  111.  
  112.     void DrawSpriteFX(short num, short x, short y, OPENGL_SPRITEFX& fx); // Draw Sprotes with FX
  113.  
  114.     bool LoadSurface(GLuint num, LPCTSTR szFileName, bool GrayScale=false); // Load a Background Surface
  115.     void PasteSurface(GLuint num, short scx=0, short scy=0); // Show a Background Surface
  116.  
  117.     void Particles(OPENGL_PARTICLE& pt, COLORREF color=0); // Add Partikels, No Color will use struct-values
  118.     void DrawParticles(); // Call to draw particles if any required
  119.     inline unsigned short FlipScreens(void); // Flip Screens, Kill WinMessages, Return Elapsed Time
  120.  
  121.  
  122. /////////////////////////////////////////////////////////////////////////////////////////
  123. // DATA
  124. /////////////////////////////////////////////////////////////////////////////////////////
  125. public:
  126.     void ResizeAuto();
  127.     void BlendToSurface(int fsurface, int tsurface);
  128.     void FreeAll();
  129.     void FreeSurface(int num);
  130.     void FreeSprite(int num);
  131.     void GrabSurface(int num);
  132.     void DrawLine(short sx, short sy, short ex, short ey, COLORREF col);
  133.     HPALETTE hPalette;
  134.  
  135.     GLshort SpriteX[GLR_MAX_TEXTURES]; // TexSize X
  136.     GLshort SpriteY[GLR_MAX_TEXTURES]; // TexSize Y
  137.     GLshort SpriteBX[GLR_MAX_TEXTURES]; // BmpSize X
  138.     GLshort SpriteBY[GLR_MAX_TEXTURES]; // BmpSize Y
  139.     GLshort SpriteDX[GLR_MAX_TEXTURES]; // Offset X
  140.     GLshort SpriteDY[GLR_MAX_TEXTURES]; // Offset Y
  141.     struct OPENGL_RAINBOWS_WINDOW
  142.     {
  143.         HWND    hwnd;
  144.         int        width;
  145.         int        height;
  146.         int        bpp;
  147.         bool    fullscreen;
  148.     } m_WND;
  149.  
  150. private:
  151.     struct OPENGL_RAINBOWS_SURFACE
  152.     {
  153.         GLuint        txt [64][64]; // Textures
  154.         GLushort    sizx[64][64]; // Size of each Texture X
  155.         GLushort    sizy[64][64]; // Size of each Texture Y
  156. //        GLushort    offy;        // 
  157.         GLubyte        usex;        // Used Texture-Panels X
  158.         GLubyte        usey;        // Used Texture-Panels Y
  159.     } m_Surface[GLR_MAX_SURFACE];
  160.  
  161.  
  162.  
  163.     bool    m_IsActive;                    // Can perform Rendering
  164.     HGLRC    m_hRC;                        // Permenant Rendering context
  165.     GLuint    Texture[GLR_MAX_TEXTURES];    // Texture
  166.     DWORD    m_LastTime;
  167.     unsigned short    m_FrameRate;
  168.     unsigned short    m_LastFlip;
  169.     unsigned short    m_ConstFlip;
  170.  
  171.     OPENGL_PARTICLE    m_Particle[GLR_MAX_PARTICLE];
  172.     int    m_CurrParticle;
  173. };
  174.  
  175. #endif // !defined(AFX_OPENGLRAINBOWS_H__266EBDA0_35ED_11D4_9493_F737DDF20444__INCLUDED_)
  176.  
  177. #endif //#define    OPENGL_RAINBOWS_INCLUDED_09_12_2000_16_15
  178.  
  179. //////////////////////////////////////////////////////////////////////////////////////////
  180. //                     I N L I N E S
  181. //////////////////////////////////////////////////////////////////////////////////////////
  182.  
  183.  
  184. //---------------------------------------------------------------//
  185. unsigned short    OpenGLRainbows::FlipScreens(void)
  186. //---------------------------------------------------------------//
  187. {
  188. DWORD    now;
  189. MSG        m;
  190.     SwapBuffers(::GetDC(m_WND.hwnd));
  191.     glClear(GL_COLOR_BUFFER_BIT);
  192.     m_LastFlip=0;
  193.     while (m_LastFlip<m_FrameRate)// Slow to xx Hz !?
  194.     {
  195.         now=timeGetTime();
  196.         m_LastFlip+=(unsigned short)(now-this->m_LastTime);
  197.         this->m_LastTime=now;
  198.  
  199.         // Peek & Translate Win Message
  200.         if (::PeekMessage(&m, this->m_WND.hwnd, 0, 0, PM_REMOVE))
  201.         {
  202.             if (m.message==WM_SYSCOMMAND && m.wParam==SC_CLOSE) return 0;
  203.             ::DispatchMessage(&m);
  204.             ::DefWindowProc(this->m_WND.hwnd, m.message, m.wParam, m.lParam);
  205.         }
  206.     }
  207. return m_LastFlip;
  208. }
  209.  
  210.  
  211.